package com.yincai.carefreewater.base;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.yincai.carefreewater.inteface.OnListence;
import com.yincai.carefreewater.inteface.OnLongListence;

import java.util.List;

/**
 * Adapter
 */

public abstract class BaseRecyclerViewAdapter<T> extends RecyclerView.Adapter<ViewHodler>{
    protected OnListence mOnListence;
    protected OnLongListence onLongListence;
    public List<T> mList;
    public Context mContext;
    private int layoutId;//item布局名
    private LayoutInflater mInflater;
    public BaseRecyclerViewAdapter(List<T> mList, Context context, int layoutId){
        this.layoutId=layoutId;
        this.mContext=context;
        this.mList=mList;
        mInflater= LayoutInflater.from(context);
    }
    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(layoutId,parent,false);
        ViewHodler viewHodler=new ViewHodler(view);
        return viewHodler;
    }

    public abstract void BindViewHolder(ViewHodler holder, T data,int position);
    @Override
    public void onBindViewHolder(ViewHodler holder, int position) {
        BindViewHolder(holder,mList.get(position),position);

    }

    @Override
    public int getItemCount() {
        return mList==null?0:mList.size();
    }

    public void setOnClickListence(OnListence onClickListence){
        this.mOnListence=onClickListence;

    }
    public void setOnLongClickListence(OnLongListence onClickListence){
        this.onLongListence=onClickListence;

    }
}
